package com.vast.ui.component.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;


public class TextBoxLogger implements Logger {
	public Display display = null;
	public Text textBox    = null;
	List<String> logMessages = null;
	
	public TextBoxLogger(Display display, Text textBox) {
		this.display = display;
		this.textBox = textBox;
		logMessages = new ArrayList<String>();
	}

	public void writeEntry(Collection entry) {
		// TODO Auto-generated method stub
		for(String text : (Collection<String>)entry){
			logMessages.add(text);
		}
		String log = new String();
		for(String text : logMessages){
			log = log + text + "\n";
		}
		final String outputLog = new String(log);
		display.asyncExec(new Runnable() {
			public void run() {
				textBox.setText(outputLog);
			}
		});
	}

	public void writeEntry(String entry) {
		// TODO Auto-generated method stub
		logMessages.add(entry);
		String log = new String();
		for(String text : logMessages){
			log = log + text + "\n";
		}
		final String outputLog = new String(log);
		display.asyncExec(new Runnable() {
			public void run() {
				textBox.setText(outputLog);
			}
		});
	}

}
